package Cluster;

import java.util.ArrayList;

import XmlLoader.Position;

public class MainTraj {
	
	public static final int MAINTRAJ_AVG = 0;
	
	public static Trajectory Average(ArrayList<Trajectory> trajList, int maxLength) {
		Trajectory newMainTraj = new Trajectory();
		int indexLength = 0, indexTraj = 0;
		int sumP_x = 0, sumP_y = 0;
		int addTime = 0;
		while(indexLength < maxLength) {
			indexTraj = 0;
			sumP_x = 0;
			sumP_y = 0;
			addTime = 0;
			while(indexTraj < trajList.size()) {
				Trajectory getTraj = trajList.get(indexTraj);
				if(getTraj.GET001_length() > indexLength) {
					Position getP = getTraj.listPoint.get(indexLength);
					sumP_x = sumP_x + getP.x;
					sumP_y = sumP_y + getP.y;
					addTime = addTime + 1;
				}
				indexTraj = indexTraj + 1;
			}
			newMainTraj.ACT001_addPoint(sumP_x / addTime, sumP_y / addTime);
			indexLength = indexLength + 1;
		}
		return newMainTraj;
	}
}
